package com.naico.core.pojo;

import com.naico.core.service.comparator.DebtOrderComparator;

import java.io.Serializable;
import java.util.Collections;
import java.util.List;

/**
 * User: Dawood Ajaz
 * Date: Dec 29, 2008
 * Time: 7:18:58 PM
 */
public class DebtInformationRequest implements Serializable {
    private static final long serialVersionUID = 1L;
    private double extraPayment;
    private DebtOrderComparator debtOrder;
    private List<DebtInformation> debtInformationList;

    public static final int LOWEST_TO_HIGHEST = 1;
    public static final int HIGHEST_TO_LOWEST = 2;


    public double getExtraPayment() {
        return extraPayment;
    }

    public void setExtraPayment(double extraPayment) {
        this.extraPayment = extraPayment;
    }

    public DebtOrderComparator getDebtOrder() {
        return debtOrder;
    }

    public void setDebtOrder(DebtOrderComparator debtOrder) {
        this.debtOrder = debtOrder;
    }

    public List<DebtInformation> getDebtInformationList() {
        return debtInformationList;
    }

    public void setDebtInformationList(List<DebtInformation> debtInformationList) {
        this.debtInformationList = debtInformationList;
    }

    /**
     * Gets the total Minimum payments of all the Debts
     *
     * @return double value for the total of minimum payments
     */
    public double getTotalMinimumPayment() {
        double totalMinimumPayment = 0.0;

        if (this.debtInformationList == null)
            return totalMinimumPayment;

        for (DebtInformation debtInfo : this.debtInformationList) {
            totalMinimumPayment += debtInfo.getMinimumPayment();
        }
        return totalMinimumPayment;
    }

    /**
     * Gets the total Actual payments of all the Debts
     *
     * @return double value for the total of actual payments
     */
    public double getTotalActualPayment() {
        double totalActualPayment = 0.0;

        if (this.debtInformationList == null)
            return totalActualPayment;

        for (DebtInformation debtInfo : this.debtInformationList) {
            totalActualPayment += debtInfo.getActualPayment();
        }
        return totalActualPayment;
    }

    /**
     * Gets the total balance of all the Debts
     *
     * @return double value for the total of balance
     */
    public double getTotalBalance() {
        double totalBalance = 0.0;

        if (this.debtInformationList == null)
            return totalBalance;

        for (DebtInformation debtInfo : this.debtInformationList) {
            totalBalance += debtInfo.getBalance();
        }
        return totalBalance;
    }

    /**
     * Gets the total balance of all the Debts
     *
     * @return double value for the total of balance
     */
    public double getAverageInterest() {
        double totalInterest = 0.0;

        if (this.debtInformationList == null)
            return totalInterest;

        for (DebtInformation debtInfo : this.debtInformationList) {
            totalInterest += debtInfo.getInterestRate();
        }
        return totalInterest / debtInformationList.size();
    }


    public void sortedDebtInformationList() {
        if (debtInformationList != null) {
            Collections.sort(debtInformationList, this.getDebtOrder());
        }
    }
}
